import { useRef } from 'react';

/**
 * @description: 返回能够获取上下文变量，且缓存的函数
 * @param {*} fn
 */
export default function useContextCalback(fn) {
  const fnRef = useRef(fn);
  fnRef.current = fn;
  const cacheRef = useRef((...args) => fnRef.current(...args));
  return cacheRef.current;
}
